<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript" src="../js/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
var currentPage = ${currentPage};
var totalPage = ${totalPage};
$(document).ready(function(){
	$(":button:eq(1)").click(function(){
		location.href="goodsadd.jsp";
	});
	
	$(":button:first").click(function(){
		currentPage = 1;
		getList();
	});
	function getList(){
		var namekey = $("#namekey").val();
		location.href="GetGoodsListServlet?currentPage="+currentPage+"&namekey="+namekey;
	}

	
	function del(id){
		if(confirm("是否确定删除？")){
			location.href="DelGoodsServlet?id="+id+"&currentPage="+currentPage;
		}
	}
	function update(id,name,price,account){
		location.href="goodsadd.jsp?id="+id+"&name="+name+"&price="+price+"&account="+account+"&currentPage="+currentPage;
	}
	function top(id,goodsShelves){
		goodsShelves=1;
		location.href="GoodsShelvesServlet?id="+id+"&goodsShelves="+goodsShelves+"&currentPage="+currentPage;
	}
	function below(id,goodsShelves){
		goodsShelves=0;
		location.href="GoodsShelvesServlet?id="+id+"&goodsShelves="+goodsShelves+"&currentPage="+currentPage;
	}

	
	
	$(".page:first").click(function(){
		currentPage = 1;
		getList();
	});
	$(".page:eq(1)").click(function(){
		if(currentPage==1){
			alert("当前已经是第一页啦");
		}else{
			currentPage--;
			getList();
		}
	});
	$(".page:eq(2)").click(function(){
		if(currentPage==totalPage){
			alert("当前已经是最后一页啦");
		}else{
			currentPage++;
			getList();
		}
	});
	$(".page:eq(3)").click(function(){
		currentPage = totalPage;
		getList();
	});
	
	
	function os(goodsShelves){
		if(goodsShelves==0){
			$("#gs").html("下架");
			$(":button:eq(3)").hide();
		}
		if(goodsShelves==1){
			$("#gs").html("上架");
			$(":button:eq(2)").hide();
		}
		
	}
});
</script>
</head>
<body>
商品名称：<input type="text" id="namekey" value="${param.namekey}">
<input type="button" value="搜索">
<input type="button" value="添加">
<table border="1" width="80%">
	<tr><th>商品名称</th><th>价格</th><th>库存</th><th>状态</th><th>操作</th>
	</tr>
	<c:forEach items="${list}" var="b">
		<tr>
			<td>${b.goodsName}</td>
			<td>${b.goodsPrice}</td>
			<td>${b.goodsAccount}</td>
			<td id="gs" onclick="os(${b.goodsShelves});"></td>
			<td>
				<input type="button" value="上架" onclick="top(${b.goodsId},${b.goodsShelves})">
				<input type="button" value="下架" onclick="below(${b.goodsId},${b.goodsShelves})">
				<input type="button" value="删除" onclick="del(${b.goodsId})">
				<input type="button" value="修改" onclick="update(${b.goodsId},
				'${b.goodsName}',${b.goodsPrice},${b.goodsAccount})">
			</td>
		</tr>
	</c:forEach>
</table>
<input type="button" value="第一页" class="page">
<input type="button" value="上一页" class="page">
<input type="button" value="下一页" class="page">
<input type="button" value="最后页" class="page">
${currentPage}/${totalPage}
</body>
</html>